<template>
    <h1>用户ID为:{{ $route.params.id }}</h1>
    <input type="button" @click="toHome()" value="回到首页">

</template>
<script setup>
import { onBeforeRouteLeave, useRouter } from 'vue-router';
let router = useRouter()
function toHome() {
    router.push('/home')
}
onBeforeRouteLeave((to, from, next) => {
    if (to.path !== '/user') {
        alert('您正在离开用户页面！')
        next()
    }
})
</script>